﻿using KPIS.GERP.GAMS.APP.App_UI.Commons;
using KPIS.GERP.GAMS.DAL;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace KPIS.GERP.GAMS.APP.App_UI.Forms
{
    public partial class PrintExcel : System.Web.UI.Page
    {
        Main main = new Main();
        D_ACM_GENERAL_Ledger gl = new D_ACM_GENERAL_Ledger();
        D_ACM_MiscReport misc = new D_ACM_MiscReport();
        MailMerge mailMerge = new MailMerge();

        protected void Page_Load(object sender, EventArgs e)
        {
            switch (Request.QueryString["Type"])
            {
                case "Ledger":
                    string strTranSeq = Request.QueryString["Id"];

                    var tranInfo = gl.GetHeaderInfo(Convert.ToInt32(strTranSeq));
                    var dtlsList = misc.ReportAdjust(strTranSeq);

                    Dictionary<string, string> dic = new Dictionary<string,string>();
                    dic.Add("L2", tranInfo.tran_code);
                    dic.Add("L3", tranInfo.tran_date.HasValue ? tranInfo.tran_date.Value.ToLongDateString() : "");
                    dic.Add("C5", tranInfo.tran_name);

                    Dictionary<string, DataTable> dic2 = new Dictionary<string, DataTable>();
                    dic2.Add("A8", dtlsList);

                    mailMerge.MergeExcel(Response, Server.MapPath("~/Reports/Templates/Adjust.xlsx"), string.Format("Voucher-{0}", DateTime.Now.ToString("yyyyMMddHHmmssffff")), dic2, dic);
                    break;
            }
        }
    }
}